package com.gpframework.module.module.service.impl;

import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gpframework.module.module.mapper.GpAgentCompanyMapper;
import com.gpframework.module.module.domain.GpAgentCompany;
import com.gpframework.module.module.domain.vo.GpAgentCompanyVo;
import com.gpframework.module.module.domain.vo.GpAgentCompanyExcel;
import com.gpframework.module.module.service.IGpAgentCompanyService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import com.gpframework.common.utils.StringUtils;

import java.util.ArrayList;
import java.util.List;
/**
 * @ClassName GpAgentCompany
 * @Author gpframework
 * @Date 2024-01-08
 * @Version 1.0.0
 * @Description 清关公司管理Service业务层处理
 */
@Service
public class GpAgentCompanyServiceImpl extends ServiceImpl<GpAgentCompanyMapper, GpAgentCompany> implements IGpAgentCompanyService {

    /**
     * @Description 查询列表返回VO 用于返回给前端的列表接口
     * @Author gpframework
     * @Date 2024-01-08
     * @Param [lqw]
     * @Return List<GpAgentCompanyVo>
     */
    @Override
    public List<GpAgentCompanyVo> listVo(QueryWrapper<GpAgentCompany> lqw) {
        return this.baseMapper.listVo(lqw);
    }

    /**
     * @Description 通过查询详情VO 用于返回给前端的列详情接口
     * @Author gpframework
     * @Date 2024-01-08
     * @Param [id]
     * @Return GpAgentCompanyVo
     */
    @Override
    public GpAgentCompanyVo getVoById(Long id) {
        return this.baseMapper.getVo(id);
    }

    @Override
    public List<GpAgentCompanyExcel> gpAgentCompanyImport(List<GpAgentCompanyExcel> excelList, Long brandId, Long storeId) {
        //导入失败的列表
        List<GpAgentCompanyExcel> failureList = new ArrayList<>();
        //清关公司管理
        GpAgentCompany gpAgentCompany;

        for (int i = 0; i < excelList.size(); i++) {
            GpAgentCompanyExcel excel = excelList.get(i);
            if (StringUtils.isNull(excel)) {
                excel = new GpAgentCompanyExcel();
                excel.setSubscript(i+1);
                excel.setMsg("读取数据失败");
                failureList.add(excel);
                continue;
            }
            gpAgentCompany = Convert.convert(new TypeReference<GpAgentCompany>() {}, excel);
            this.save(gpAgentCompany);
        }
        return failureList;
    }
}
